# 练习使用requests库访问下面网站并保存网页原始内容（提示：善用dir, help）：
# https://detail.zol.com.cn/cpu_advSearch/subcate28_1.html
# https://www.2345.com/
# https://music.163.com/
import requests
import urllib

urls = [
    "https://www.2345.com/",
    "https://music.163.com/"
]

for url in urls:
    try:
        response = requests.get(url)
        if response.status_code == 200:
            page_content = response.text
            file_name = url.split('/')[-1].replace('.', '_') + '.html'
            with open(file_name, 'w', encoding='utf-8') as file:
                file.write(page_content)
            
            print(f"Successfully saved {url} to {file_name}")
        else:
            print(f"Failed to retrieve {url} with status code {response.status_code}")
    except requests.RequestException as e:
        print(f"Error retrieving {url}: {e}")